package com.rbac.interfaces.controller;

import com.rbac.application.service.ProfileService;
import com.rbac.common.annotation.OperationLog;
import com.rbac.common.result.Result;
import com.rbac.domain.dto.request.PasswordChangeRequest;
import com.rbac.domain.dto.request.ProfileUpdateRequest;
import com.rbac.domain.dto.response.UserInfoResponse;
import com.rbac.domain.entity.OperationLog;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "个人中心", description = "个人中心相关接口")
@RestController
@RequestMapping("/profile")
@RequiredArgsConstructor
public class ProfileController {

    private final ProfileService profileService;

    @Operation(summary = "获取个人信息")
    @GetMapping("/info")
    public Result<UserInfoResponse> getCurrentUserProfile() {
        return Result.success(profileService.getCurrentUserProfile());
    }

    @Operation(summary = "更新个人信息")
    @PutMapping("/info")
    @OperationLog("更新个人信息")
    public Result<UserInfoResponse> updateProfile(@Validated @RequestBody ProfileUpdateRequest request) {
        return Result.success("个人信息更新成功", profileService.updateProfile(request));
    }

    @Operation(summary = "修改密码")
    @PutMapping("/password")
    @OperationLog("修改密码")
    public Result<Void> changePassword(@Validated @RequestBody PasswordChangeRequest request) {
        profileService.changePassword(request);
        return Result.success("密码修改成功");
    }

    @Operation(summary = "获取我的操作日志")
    @GetMapping("/logs")
    public Result<List<com.rbac.domain.entity.OperationLog>> getMyOperationLogs(@RequestParam(defaultValue = "10") int limit) {
        return Result.success(profileService.getMyOperationLogs(limit));
    }
}